List - Exercises
#Write a program that stores the names of Five mountaints
# in a list called movies.
"""
1. Print the whole list
2. Print first and last mountain in the list
3. Change the second mountain to a new title of your choice
4. Print the updated list
"""
mountains = ["Everest","Kanchanjunga","Lhoste", "Yalung Khang","Makalu"]
# displaying all mountains
print(mountains)
# displaying first and last mountains
print("First : ",mountains[0], " Last: ",mountains[-1])
#changing second mountain of the list
mountains[1] = "Annapurna"
print(mountains)
"""
You have a list of Books: Data Mining, Data Structure, Python Programming, Complete Java Reference, Database.
Display all books except first and last.
Add new book Design Patterns to the end of the list.
Remove Complete Java Reference book
Print the books in ascending order
"""
books =["Data Mining","Data Structure","Python Programming","Complete Java Reference","Database"]
print(books)
# slice books excluding first and last books
slice = books[1:-1]
print(slice)
# Adding new book Design Patterns
books.append("Design Patterns")
print(books)
# Remove Java Complete Reference book
books.remove("Complete Java Reference")
print(books)
# Soring books
books.sort()
print(books)
# combine two lists
# add new item to the combined list
# Remove an item from the list
# Display total number of items
# Print sorted list of all members
list1 = [8848,8586,8516,8505]
list2 = [8476,8463,8413,8400,8201]
# combine two lists
combined_list = list1 + list2
print(combined_list)
# add new item
combined_list.append(8167)
print(combined_list)
# remove an item
combined_list.remove(8400)
print(combined_list)
# display total items of the list
print("Number of items: ",len(combined_list))
# display sorted list
combined_list.sort()
print(combined_list)